var a = getApp();

Page({
    data: {
        language: "",
        orderType: "",
        member_id: "",
        api: "",
        selected: 0,
        waitPay: [],
        pay: [],
        review: [],
        invalid: [],
        all: [],
        loading: !1,
        allLoaded: !1,
        goload: !1,
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(a) {
        a.supplier && (this.setData({
            orderType: a.supplier
        }), a.member_id && this.setData({
            member_id: a.member_id
        }));
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {
        this._initData(), "supplier" == this.data.orderType ? this._getSupplierNetData() : this._getNetData(this.data.selected);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        "supplier" != this.data.orderType && (this.data.isLoadMore ? this.getMoreData(this.data.selected) : console.log("没有更多数据"));
    },
    onShareAppMessage: function() {},
    _initData: function() {
        this.setData({
            page: 1,
            goload: !0,
            total_page: 0,
            loading: !0,
            allLoaded: !1,
            isLoadMore: !0
        });
    },
    _getSupplierNetData: function() {
        0 == this.data.selected ? this.setData({
            api: "plugin.supplier.frontend.withdraw-log.index"
        }) : 1 == this.data.selected ? this.setData({
            api: "plugin.supplier.frontend.withdraw-log.applying"
        }) : 2 == this.data.selected ? this.setData({
            api: "plugin.supplier.frontend.withdraw-log.pending"
        }) : 3 == this.data.selected ? this.setData({
            api: "plugin.supplier.frontend.withdraw-log.already"
        }) : 4 == this.data.selected && this.setData({
            api: "plugin.supplier.frontend.withdraw-log.reject"
        });
        var t = this, e = a.getNetAddresss(t.data.api);
        e += "&member_id=" + t.data.member_id, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var s = e.data;
                    t.setData({
                        total_page: s.total,
                        allLoaded: !1
                    }), t.data.total_page || t.setData({
                        total_page: 0
                    }), 0 == t.data.selected ? t.setData({
                        all: s.data
                    }) : 1 == t.data.selected ? t.setData({
                        review: s.data
                    }) : 2 == t.data.selected ? t.setData({
                        waitPay: s.data
                    }) : 3 == t.data.selected ? t.setData({
                        pay: s.data
                    }) : 4 == t.data.selected && t.setData({
                        invalid: s.data
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    _getNetData: function(t) {
        var e = "";
        0 == t ? e = "" : 1 == t ? e = "0" : 2 == t ? e = "1" : 3 == t ? e = "2" : 4 == t && (e = "-1");
        var s = this;
        s.setData({
            isLoadMore: !1,
            page: 1
        });
        var i = a.getNetAddresss("finance.withdraw.withdraw-log");
        i += "&status=" + e, a._getNetWork({
            url: i,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    s.setData({
                        allLoaded: !1,
                        isLoadMore: !0,
                        total_page: t.data.last_page
                    }), s.data.total_page || s.setData({
                        total_page: 0
                    });
                    var e = t.data.data;
                    0 == s.data.selected ? s.setData({
                        all: e
                    }) : 1 == s.data.selected ? s.setData({
                        review: e
                    }) : 2 == s.data.selected ? s.setData({
                        waitPay: e
                    }) : 3 == s.data.selected ? s.setData({
                        pay: e
                    }) : 4 == s.data.selected && s.setData({
                        invalid: e
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    swichTabTItem: function(a) {
        var t = a.detail.index;
        this.setData({
            selected: t
        }), "supplier" === this.data.orderType ? this._getSupplierNetData() : this._getNetData(this.data.selected);
    },
    gopresentationDetails: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/member/presentationDetails/presentationDetails?record_id=" + t
        });
    },
    getMoreData: function(t) {
        var e = "";
        0 == t ? e = "" : 1 == t ? e = "0" : 2 == t ? e = "1" : 3 == t ? e = "2" : 4 == t && (e = "-1");
        var s = this;
        if (s.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            s.setData({
                page: this.data.page + 1
            });
            var i = a.getNetAddresss("finance.withdraw.withdraw-log");
            a._getNetWork({
                url: i,
                data: {
                    status: e,
                    page: s.data.page
                },
                success: function(a) {
                    s.setData({
                        isLoadMore: !0
                    });
                    var t = a.data;
                    if (1 == t.result) {
                        var e = t.data.data;
                        0 == s.data.selected ? s.setData({
                            all: s.data.all.concat(e)
                        }) : 1 == s.data.selected ? s.setData({
                            review: s.data.review.concat(e)
                        }) : 2 == s.data.selected ? s.setData({
                            waitPay: s.data.waitPay.concat(e)
                        }) : 3 == s.data.selected ? s.setData({
                            pay: s.data.pay.concat(e)
                        }) : 4 == s.data.selected && s.setData({
                            invalid: s.data.invalid.concat(e)
                        });
                    } else s.setData({
                        page: s.data.page - 1,
                        isLoadMore: !1
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    }
});